/**
 * Created by xiangyufang on 2016/10/12.
 */
;(function($,window,document,undefined){
    /***全局变量初始化 start***/
    var DTTABLE;
    var $table = $('#JQ_table');
    var $inputs = $(".JQ-xyf-ids");
    var ids = [];
    $inputs.each(function () {
        var $this = $(this);
        ids.push($this.val());
    });
    var $pipe = $('#JQ_pipeline').select3().fit($('#JQ_pile').val());
    /***全局变量初始化 end***/

    DyyBase.ajax(cleanPipeApi.url_clean_history_evalData(),DyyBase.convertToArr({ids:ids}),function(dataset){
        if(dataset.bool){
            var head_meg = dataset.result.headValue;
            if(head_meg){
                $("#JQ_clean_times").text(head_meg.countNum);
                $("#JQ_clean_speed").text(head_meg.avgSpeed);
                $("#JQ_clean_water").text(head_meg.sewage);
                $("#JQ_clean_goods").text(head_meg.dirt);
            }else{
                $(this).MSG({
                    content: '测试数据未填充！'
                });
                return false;
            }
            var ListData = dataset.result.listValue;
            if(ListData){
                $('#JQ_type').val(ListData[0].type);
            }
            drawChart(ListData);
            drawTable(ListData);
        }
    });

    function drawChart(data){
        if(data){
            var dataLine = [];
            var dataMarks = [];
            var dataSqureWater = [];
            var dataSqureGoods = [];
            var $lineChart = $('#lineChart');
            var $paneChart = $('#paneChart');
            $paneChart.show();
            $lineChart.show();
            for(var i=0; i<data.length;i++){
                if(data[i].pressDif == null || data[i].pressDif == undefined || data[i].pressDif == ''){
                    dataLine.push(0);
                }else{
                    dataLine.push(data[i].pressDif);
                }
                if(data[i].pagDateTime == null || data[i].pagDateTime == undefined || data[i].pagDateTime == ''){
                    dataMarks.push('');
                }else{
                    dataMarks.push(data[i].pagDateTime.slice(0,10));
                }
                if(data[i].sewage == null || data[i].sewage == undefined  || data[i].sewage == ''){
                    dataSqureWater.push(0);
                }else{
                    dataSqureWater.push(data[i].sewage);
                }
                if(data[i].dirt == null || data[i].dirt == undefined || data[i].dirt == '' ){
                    dataSqureGoods.push(0);
                }else{
                    dataSqureGoods.push(data[i].dirt);
                }
            }
            $lineChart.loadLine(dataLine,dataMarks);
            $paneChart.loadPane(dataSqureWater,dataSqureGoods,dataMarks);
            //var data1 = [34,24,90];
            //var data2 = [56,90,333];
            //var data3 = ['sdfs','sdf','sfd'];
            //$lineChart.loadLine(data1,data3);
            //$paneChart.loadPane(data1,data2,data3);
        }else{
            $('#lineChart_null').show();
            $('#JQ_data_bull').show();
        }
    }



        //**表格数据**
    function drawTable(data){
        var Tdata = DyyBase.clearNull(data);
        DTTABLE = $table.DataTable({
            'language': {
                'zeroRecords': DyyBase.table_empty()
            },
            'info': false,
            'paging': false,
            'autoWidth': false,
            'order': [],
            'serverSide': false,
            'pageLength': 1000,
            'ordering': false,
            'processing': false,
            'searching': false,
            'lengthChange': false,
            'data': Tdata,
            'columns': [
                {
                    data: 'pagDateTime',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                },
                {
                    data: 'pagTool',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                },
                {
                    data: 'type',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                },
                {
                    data: 'sewage',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                },
                {
                    data: 'dirt',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                },
                {
                    data: 'discription',
                    render: function (data) {
                        return '<span title="' + data + '">' + data + '</span>';
                    }
                }
            ]
        });
    }

    $('#JQ_export_pdf').click(function(){
        var projectName = $pipe.val('text') +  $('#JQ_type').val();
        DyyBase.isLogin(function(){
            $(this).EXPT({
                type: 'name',
                name: projectName + '评价结果',
                yesBtnAct: function(callback,fname){
                    callback();
                    canvasPdf.exportHtmlPdf({
                        dom: $('#JQ_chart_div'),
                        server: DyyBase.root_path + '/comm/downImgPdf.json',
                        param: {
                            fileName: fname,
                            name: fname
                        }
                    });
                }
            });
        });
    });



})(jQuery,window,document);